package structural.proxy.dynamic_proxy.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @ClassName: MyInvocationHandler
 * @Description: 自己实现的调用处理器（基于JDK的动态代理)
 * @Author: liu-hao
 * @Date: 2023-04-09 22:09
 * @Version: 1.0
 **/
public class MyInvocationHandler implements InvocationHandler {

    private Object target;

    public MyInvocationHandler(Object target) {
        this.target = target;
    }

    private void before() {
        System.out.println("处理请求之前");
    }

    private void after() {
        System.out.println("处理请求之后");
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        before();
        Object result = method.invoke(this.target, args);
        after();
        return result;
    }
}
